<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>个人资料(租户)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../../taofang/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../../../taofang/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="../../../taofang/css/TenantCentre.css">
    <link rel="stylesheet" href="../../../taofang/css/home.css">
</head>
<body>


<%@include file="top.jsp"%>


<div class="col-md-9 zy5">
    <p class="zy51">个人资料</p>
    <p class="zy52"></p>
    <div class="zy53">
        <img src="../../../taofang/img/zy53.png">基本账号资料
    </div>
    <hr>
    <div class="zy54">
        头像:
        <img class="img-circle zy56" src="../../../taofang/img/h2.png">
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal1">修改</button>
        <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="Pic()">&times;</button>
                        <h4 class="modal-title" id="myModalLabel1">更改头像</h4>
                    </div>

                    <div id="Pic">

                    </div>




                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div> <hr>
    <div class="zy54">
        账号:
        ${register.account}
    </div>
    <div class="zy54">
        密码:
        <span id="span" class="zy56" style="display: none">${register.password}</span>
        <span id="spanpwd" class="zy56">*****</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal2">修改</button>
        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel2">密码更改</h4>
                    </div>
                    &nbsp;修改密码:
                    <input id="pwd" class="zy56" type="password" placeholder="请输入更改的密码&nbsp;(6-8位,字母或者数字)" onblur="pwd1()" onfocus="pwd11()">
                    <span style="color: red;display: none" id="pwdspan1">密码格式不对(6-8位字母、数字)</span>
                    <span id="pwdspan2" style="color: red;display: none">密码与原密码一样</span>
                    <br>
                    &nbsp;确认密码:
                    <input id="pwd2" class="zy56" type="password" placeholder="请再次输入更改的密码" onblur="pwd4()" onfocus="pwd44()">
                    <span style="color: red;display: none" id="pwdspan4">密码与上面密码不一致</span>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changepwd()" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div> <hr>
    <div class="zy54">
        手机:
        <span id="phonespan" class="zy56">${tenant.phone}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal3">修改</button>
        <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel3">手机号更改</h4>
                    </div>
                    &nbsp;&nbsp;&nbsp;
                    <input id="phone" class="zy56" type="text" placeholder="请输入更改的手机号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changephone()" class="btn btn-primary" data-dismiss="modal">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div> <hr>
    <div class="zy54">
        姓名:
        <span id="namespan" class="zy56">${tenant.name}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal4">修改</button>
        <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel4">姓名添加修改</h4>
                    </div>
                    &nbsp;&nbsp;&nbsp;
                    <input id="name" class="zy56" type="text" placeholder="请输入姓名(10个字符以内)">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changename()" data-dismiss="modal" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div> <hr>
    <div class="zy54">
        身份证号:
        <span id="identityspan"class="zy56">${tenant.identityCardNumber}</span>
        <button id="hide" class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal5">认证</button>
        <div class="modal fade" id="myModal5" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel5">身份认证(<span style="color: red">身份一旦认证就无法更改</span>)</h4>
                    </div>
                    &nbsp;&nbsp;&nbsp;
                    <input class="zy56" id="identity" type="text" placeholder="请输入身份证号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="insertIdentity()" data-dismiss="modal" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div> <hr>
    <div class="zy54">
        <span style="float: left">性别:</span>
        <div style="padding-top: 2%">
                <select id='gender' onchange="changegender()" class="form-control zy577">
                    <option <c:if test="${tenant.gender==true}">selected</c:if>>男</option>
                    <option <c:if test="${tenant.gender==false}">selected</c:if>>女</option>
                </select>
        </div>
    </div>
</div>


<%@include file="bottom.jsp"%>
<input type="hidden" id="registerId" value="${register.id}">
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/layui/layui.js"></script>

<script>


    $(function(){
        $("#Pic").load("/taofang/Tenant/Pic.action");
    })




    layui.use(['upload','element'],function(){
        let upload = layui.upload;//初始化
        let element = layui.element;//初始化进度条
        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '/taofang/Tenant/lay.action' //改成您自己的上传接口
            ,done: function(res){
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', "taofang/img"+res.data);
                console.log(res);
            },
            // progress: function(n, elem){
            //     var percent = n + '%' //获取进度百分比
            //     element.progress('demo', percent); //可配合 layui 进度条元素使用
            //     //以下系 layui 2.5.6 新增
            //     console.log(elem); //得到当前触发的元素 DOM 对象。可通过该元素定义的属性值匹配到对应的进度条。
            // }
        });
    })



    $(function () {
        let identityspan = document.getElementById("identityspan").innerText;
        if (identityspan!=""){
        let hide = document.getElementById("hide").style.display="none";
        }
    })






    function pwd1() {
        let pwd = $("#pwd").val();
        let pwdspan = $("#span").text();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        if (pwd==pwdspan){
            pwdspan2.style.display="inline"
        }
        if (!(/^[a-zA-Z0-9]{6,8}$/).test(pwd) && pwd!=""){
            pwdspan1.style.display="inline"
        }


    }


    function pwd11() {
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        pwdspan2.style.display="none"
        pwdspan1.style.display="none"
    }


    function pwd4() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan4 = document.getElementById("pwdspan4")
        if (pwd!=pwd4 && pwd4!=""){
            pwdspan4.style.display="inline"
        }
        if (pwd4==""){
            pwd4.style.display="none"
        }

    }


    function pwd44() {
        let pwdspan4 = document.getElementById("pwdspan4")
        pwdspan4.style.display="none"
    }

    function changepwd() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        // let pwdspan3 = document.getElementById("pwdspan3")
        let pwdspan4 = document.getElementById("pwdspan4")
        if(  pwdspan2.style.display=="none" &&
            pwdspan1.style.display=="none" && pwdspan4.style.display=="none" && pwd!="" && pwd4!=""){
            let registerId = $("#registerId").val();
            let datas = {"id": registerId, "password": pwd}
            $.post('/taofang/Tenant/changepwd.action', datas, function (data) {
                if (data.code == 200) {
                    alert("修改成功")
                    window.location="/taofang/login/check.action"
                }else{
                    alert("修改失败")
                }
            })
        }else{
            alert("请输入正确的修改密码")
        }
    }

    function changephone() {
        let phone = $("#phone").val();
        let span = $("#phonespan").text();
        if (phone!=""){
                if(phone==span){
                    alert("修改的手机号不能和原来手机号一样")
                }else {
                    if ((/^1(3[0-9]|5[0-9]|8[0-9])[0-9]{8}$/).test(phone)) {
                        let tenantId = $("#tenantId").val();
                        let datas = {"id": tenantId, "phone": phone}
                        $.post('/taofang/Tenant/changephone.action', datas, function (data) {
                            if (data.code == 200) {
                                alert("修改成功")
                                let phonespan = document.getElementById("phonespan").innerText = data.data.phone;
                            }
                        })

                    } else {
                        alert("请输入正确的手机号")
                    }

                }
        }else{
            alert("修改不能为空")
        }
    }

    function changename() {
        let name = $("#name").val();
        let names=$("#namespan").text();
        if (name!=""){
            if (name==names){
                alert("修改的姓名不能和原来姓名一样")
            }else {
                if (name.length<11) {
                    let tenantId = $("#tenantId").val();
                    let datas = {"id": tenantId, "name": name}
                    $.post('/taofang/Tenant/changename.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("修改成功")
                            let namespan = document.getElementById("namespan").innerText = data.data.name;
                        }
                    })
                }else{
                    alert("姓名不能超过10字符")
                }
            }
        }else{
            alert("修改不能为空")
        }
    }


    function changegender() {
        let genval = $("#gender").val();
        let vals;
        if ("男"==genval){
            vals = "true";
        }else{
            vals="false";
        }

        let tenantId = $("#tenantId").val();
        let datas={"id":tenantId,"gender":vals}
        $.post('/taofang/Tenant/changegender.action',datas,function (data){
            if (data.code==200){
                alert("修改成功")
            }
     })
}
    function insertIdentity() {
            let identity = $("#identity").val();
            let tenantId = $("#tenantId").val();
            let datas = {"id":tenantId,"identity":identity}
            if(identity!=""){

                if(( /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)
                .test(identity)){
                    $.post('/taofang/Tenant/insertIdentity.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("认证成功")
                            let identityspan = document.getElementById("identityspan").innerText = data.data.identityCardNumber;
                            let hide = document.getElementById("hide").style.display = "none";
                        }
                    })
                }else{
                    alert("请输入正确的身份证号")
                }
            }else{
                alert("修改不能为空")
        }

    }




</script>






</body>
</html>
